package DP;

/**
 * @author 曹见朋
 * @create 2024-06-13-21:39
 */
public class Main198 {
    // TODO 198. 打家劫舍
    public static int rob(int[] nums) {

        int n = nums.length;

        int[] dp = new int[n];
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0], nums[1]);

        for(int i = 2; i < n; i++){
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);
        }

        return dp[n - 1];
    }

    public static void main(String[] args) {
        int[] nums = new int[]{2,7,9,3,1};
        int rob = rob(nums);
        System.out.println(rob);
    }
}
